<?php
namespace api\admin\controller;

use cmf\controller\RestBaseController;
use think\Validate;

header("Access-Control-Allow-Origin: *"); // Support CORS
header('Access-Control-Allow-Headers:x-requested-with,content-type,Device-Type,User-Token');
header('Access-Control-Allow-Methods:GET, POST, PATCH, PUT, DELETE');
header('Access-Control-Allow-Headers:Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With');

class UploadController extends RestBaseController
{
    // 用户密码修改
    public function upload()
    {

        if (empty(!$_FILES)) {

            $file = request()->file('images');
            // 移动到框架应用根目录/public/upload/ 目录下
            $info = $file->validate([
                // 'size' => 15678,
                'ext' => 'jpg,png,gif',
            ]);
            $info = $info->move(ROOT_PATH . 'public' . DS . 'upload');
            if ($info) {
                $saveName = $info->getSaveName();
                $originalName = $info->getInfo('name'); //name,type,size
                $fileSize = $info->getInfo('size');
                $suffix = $info->getExtension();
                $this->success("上传成功!", ['url' => $saveName, 'filename' => $originalName]);
            } else {
                // 上传失败获取错误信息
                $this->error($file->getError());
            }
        }

    }

}
